﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls.WebParts;
using System.ComponentModel;
using Microsoft.SharePoint.WebPartPages;
using DevSky.WebParts.WPToolParts;
using DevSky.WebParts.DBConnectWP;

namespace DevSky.WebParts
{
  public partial class DevSkyDBConnectWP
  {
    private string loadingWaitText = string.Empty;
    private string loadingWaitImagePath = string.Empty;
    private string noDataFound = string.Empty;

    [WebBrowsable(true)]
    [WebDisplayName("Include Dev-Sky CSS")]
    [Category("EDBI WP - Result Grid")]
    [Personalizable(PersonalizationScope.Shared)]
    [Description("If checked a default CSS file is added to the head section to load.")]
    public bool IncludeDefaultCSS { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(true)]
    [Category("EDBI WP - Result Grid")]
    [WebDisplayName("Wait Text")]
    [WebDescription("Please enter the progress loading text that is displayed to the user.")]
    public string LoadingWaitText
    {
      get
      {
        if (string.IsNullOrEmpty(loadingWaitText))
          return "Loading data from the server ...";
        return loadingWaitText;
      }
      set
      {
        loadingWaitText = value;
      }
    }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(true)]
    [Category("EDBI WP - Result Grid")]
    [WebDisplayName("(Animated) loading indicator image")]
    [WebDescription("Please specify an (animated) image that is displayed during data loading")]
    public string LoadingWaitImagePath
    {
      get
      {
        if (loadingWaitImagePath == null)
          return "/_layouts/images/DevSkySolutions/wp-loading.gif";
        return loadingWaitImagePath;
      }
      set
      {
        loadingWaitImagePath = value;
      }
    }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(true)]
    [Category("EDBI WP - Result Grid")]
    [WebDisplayName("No results")]
    [WebDescription("Message text when no data found")]
    public string NoDataMessage
    {
      get
      {
        if (string.IsNullOrEmpty(noDataFound))
          return "No data available.";
        return noDataFound;
      }
      set
      {
        noDataFound = value;
      }
    }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(true)]
    [Category("EDBI WP - Result Grid")]
    [WebDisplayName("Allow sorting")]
    [WebDescription("Allow sorting the results inside the grid")]
    public bool AllowSortingOnAllCoumns { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(true)]
    [Category("EDBI WP - Result Grid")]
    [WebDisplayName("Show Header")]
    [WebDescription("Switch on/off the header for the result grid")]
    public bool ShowGridHeader { get; set; }

    #region EXTENDED Information
    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public string DataBaseServer { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public string DataBaseName { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public string DataBaseUser { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public string DataBasePassword { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public string DataSource { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public string DataSourceType { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public string ConnectMode { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public string AppKey { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public string ConnectKey { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public string ConnectString { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public List<CustomDataColumn> CustomDataColumns { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public bool ShowEditLink { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public bool ShowReadOnlyLink { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public bool ShowNewLink { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public bool ShowDeleteLink { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public bool ShowCustomLinks { get; set; }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(false)]
    public string DetailDialogTitle { get; set; }
    #endregion

    #region TOOLPARTS
    public override EditorPartCollection CreateEditorParts()
    {
      DBConfigSettings editor = new DBConfigSettings("Specify database information") { ID = "DataBaseConfiguration" };
      editor.ID = this.ID + "_devksydbconfig";
      EditorPart[] parts = { editor };
      return new EditorPartCollection(parts);
    }
    #endregion
  }
}
